package com.example.demo.controller;

import com.example.demo.entity.Banner;
import com.example.demo.log.SystemControllerLog;
import com.example.demo.service.BannerService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/beeorder/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @GetMapping("/get/{id}")
    @SystemControllerLog
    public Banner getById(@PathVariable Integer id) {
//        Banner banner = bannerService.getById(id);
        Banner banner = new Banner();
        return banner != null ? banner : new Banner();
    }

    @GetMapping("/get")
    public Banner getByEntity(Banner banner) {
        return bannerService.getByEntity(banner);
    }

    @PostMapping("/list")
    @SystemControllerLog
    public List<Banner> list(@RequestBody Banner banner) {
//        List<Banner> bannerList = bannerService.listByEntity(banner);
        List<Banner> bannerList = new ArrayList<>();
        return bannerList;
    }

    @PostMapping("/insert")
    public Banner insert(@RequestBody Banner banner) {
        bannerService.insert(banner);
        return banner;
    }

    @PutMapping("/update")
    public int update(@RequestBody Banner banner) {
        return bannerService.update(banner);
    }

    @DeleteMapping("/delete/{id}")
    public int deleteOne(@PathVariable Integer id) {
        return bannerService.deleteById(id);
    }

    @DeleteMapping("/delete")
    public int deleteBatch(@RequestBody List<Integer> ids) {
        int result = 0;
        if (ids != null && ids.size() > 0) result = bannerService.deleteByIds(ids);
        return result;
    }

}
